import os
import random
import xml.etree.ElementTree as ET


def exist_obj(file,objlist):
    tree = ET.ElementTree
    tree = ET.parse(file)
    root = tree.getroot()
    for obj in root.findall('object'):
        objName = obj.find('name').text
        if objName in objlist:
            return True
    return False

PATH = 'J:\python\yolov4-tiny-keras-master\VOCdevkit\VOC2007\__ins_ps-436压缩前'
OBJ_LIST = ['鸟巢']
if __name__ == "__main__":
    xmlfilepath = os.path.join(PATH, 'Annotations')
    xmlfiles = os.listdir(xmlfilepath)
    for fileName in xmlfiles:
        if exist_obj(os.path.join(xmlfilepath, fileName),objlist=OBJ_LIST): 
            print(fileName)
